package com.iyjhsoc.game.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.iyjhsoc.game.ENUM.ConstantENUM;
import com.iyjhsoc.game.dao.TeamDAO;
import com.iyjhsoc.game.domain.VO.TeamVO;
import com.iyjhsoc.game.domain.entity.TeamDO;
import com.iyjhsoc.game.domain.entity.ZornDO;
import com.iyjhsoc.game.domain.response.Response;
import com.iyjhsoc.game.service.TeamService;
import com.iyjhsoc.game.service.ZornService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@ApiModel("队伍信息")
@RequestMapping("iyj/competition/team")
public class TeamController extends BaseController<TeamDAO, TeamDO,TeamVO>{

    @Autowired
    TeamService teamService;
    @Autowired
    ZornService zornService;

    @ApiModelProperty("队伍比赛英雄")
    @PostMapping("getTeamMatchHero")
    public Response getTeamMatchHero(@RequestBody TeamVO vo){
        return Response.SUCCESS(teamService.getTeamMatchHero(vo));
    }


    @PostMapping("saveTeam")
    public Response saveTeam(@RequestBody TeamDO teamDO){
        ZornDO byId = zornService.getById(teamDO.getZornId());
        if(byId == null){
            return Response.ERROR("战队信息错误");
        }
        QueryWrapper<TeamDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name",teamDO.getName());
        queryWrapper.eq("zorn_id",teamDO.getZornId());
        queryWrapper.eq("game_id",teamDO.getGameId());
        TeamDO one = teamService.getOne(queryWrapper);
        if(one != null){
            return Response.ERROR("战队信息已经存在");
        }
        teamDO.setZornName(byId.getName());
        boolean save = teamService.save(teamDO);
        if(save){
            return Response.SUCCESS(ConstantENUM.SAVE_SUCCESS);
        } else {
            return Response.ERROR(ConstantENUM.SAVE_ERROR);
        }
    }
}
